﻿function isPassive() {
    var supportsPassiveOption = false;
    try {
        addEventListener("test", null, Object.defineProperty({}, 'passive', {
            get: function () {
                supportsPassiveOption = true;
            }
        }));
    } catch (e) { }
    return supportsPassiveOption;
}

var myScroll;
var w = $(window).width();

function loaded() {
    if (w < 769) {
        //myScroll = new IScroll('#wrapper', { mouseWheel: true });
    }
}

function superSlide() {
    if (w > 768) {
        jQuery(".section1main").slide({ mainCell: ".bd ul", autoPlay: true });
    } else {
        TouchSlide({
            slideCell: "#section4",
            titCell: ".hd ul", //开启自动分页 autoPage:true ，此时设置 titCell 为导航元素包裹层
            mainCell: ".bd ul",
            effect: "leftLoop",
            autoPage: true,//自动分页
            autoPlay: true //自动播放
        });

        TouchSlide({
            slideCell: "#section1",
            titCell: ".hd ul", //开启自动分页 autoPage:true ，此时设置 titCell 为导航元素包裹层
            mainCell: ".bd ul",
            effect: "leftLoop",
            autoPage: true,//自动分页
            autoPlay: true //自动播放
        });
    }
}

function sub() {
    var load;
    $('#submit').on('click', function () {
        var name = $('#name').val();
        var tel = $('#tel').val();
        var yinglou = $('#yinglou').val();
        var content = $('#content').val();
        if (!!!name || !!!yinglou || !!!tel || !!!content) {
            layer.alert('请输入完整的信息');
            return false;
        }
        $.ajax({
            url: '/Handler1.ashx',
            type: 'post',
            dataType: 'html',
            data: { name: name, tel: tel, yinglou: yinglou, content: content },
            beforeSend: function () {
                load = layer.load(2);
                $('#submit').attr('disabled', true);
            },
            error: function () {
                layer.alert('提交失败');
            },
            success: function (data) {
                if (data === 'ok') {
                    layer.alert('提交成功，我们会尽快与您联系');
                } else {
                    layer.alert(data);
                }
            },
            complete: function () {
                layer.close(load);
                $('#submit').removeAttr('disabled');
            }
        })
    })

    $('#apply').on('click',
        function () {
            var phone = $('#mobile').val();
            if (!!!phone) {
                layer.alert('请输入手机号');
                return;
            }
            if (!checkMobileNum(phone)) {
                layer.alert('请输入正确的手机号');
                return;
            }
            $.ajax({
                url: '/Handler2.ashx',
                type: 'post',
                dataType: 'html',
                data: { mobile:phone },
                beforeSend: function () {
                    load = layer.load(2);
                },
                success: function (data) {
                    if (data === 'ok') {
                        layer.alert('提交成功，我们会尽快与您联系');
                    } else {
                        layer.alert(data);
                    }
                },
                complete: function () {
                    layer.close(load);
                    $('#submit').removeAttr('disabled');
                }
            });
        });
}

$(function() {
    loaded();
    superSlide();
    sub();
});

function checkMobileNum(m) {
    var reg = /^1[34578][0-9]{9}$/ig;
    return reg.test(m);
}

if (w < 769) {
    $.each($('#section4>.bd>ul>li>span'), function (i, item) {
        var obj = $(item);
        obj.css({
            'background-image': 'url(/content/images/hezuom' + (i + 1) + '.png)'
        });
    })
}
//页内跳转
//$('.nav li').on('click',
//    function () {
//        var to = $(this).data('scroll');
//        var hh = $('.header').outerHeight();
//        if (w > 768)
//            hh = 0;
//        var toH = $('.' + to).offset().top -hh;
//        $("html,body").finish().animate({ 'scrollTop': toH }, 500 * (0 + 1));
//        $(this).addClass('on').siblings().removeClass('on');
//        $('.nav').removeClass('active');
//    });

$('#nav-menu').on('click', function() {
    $('.nav').toggleClass('active');
})

$('.icon-close').on('click', function() {
    $('.nav').removeClass('active');
})
//选择地址pc切换影楼
var img = ['content/images/beijing.png', 'content/images/shanghai.png', 'content/images/tianjin.png', 'content/images/shandong.png', 'content/images/jiangsu.png', 'content/images/liaoning.png', 'content/images/jilin.png', 'content/images/heilongjiang.png', 'content/images/shanxi.png', 'content/images/shangxi.png', 'content/images/zhejiang.png', 'content/images/fujian.png', 'content/images/yunnan.png'
    , 'content/images/sichuan.png', 'content/images/anhui.png', 'content/images/chongqing.png', 'content/images/hubei.png', 'content/images/hunan.png', 'content/images/guangdong.png', 'content/images/henan.png', 'content/images/hebei.png', 'content/images/neimenggu.png', 'content/images/xinjiang.png', 'content/images/guizhou.png', 'content/images/hainan.png', 'content/images/xianggang.png',
    'content/images/shenzhen.png', , 'content/images/guangxi.png'];
$(document).ready(function () {
    $(".s2-left li").click(function () {
        var i = $(this).index();
        $(this).addClass("click").siblings().removeClass();
        $('.s2-right').find('img').attr('src', img[i]);
      
    });
});

function select(obj) {

    $("#div" + obj.value).show().siblings().hide();
    $(".s2-right").hide();
    //if (obj.value==1) {
    //    $(".s2-right").show();
    //}
    //找到内容的标签 + 点击select获得的value值，让它显示，再让他的兄弟标签隐藏。
}

$('#selectProvince').on('change', function () {
    var index = $(this).get(0).selectedIndex;
    $('#imgBox').find('div').hide().eq(index).show();
})